def best(name, type, outfile, t, recordfile):
    f = open(outfile, "w")
    for subname, items in type.iteritems():
        if subname:
            f.write((u"<h4>%s</h4>" % subname).encode("UTF-8"))
        
        items.sort(lambda x,y:cmp(x[14],y[14]),reverse=True) #sort by GB/$

        for i, item in zip(range(20), items):#                                                              #,   GB/$,   GB/$ incl sh,   link,       title,          price,    price+sh,         the rest
            s = u"<p>%i. (%f GB/$ / %f incl sh)  <a href=\"%s\">%s</a> - $%s / $%s incl sh - %s</p>\n" % (i+1, item[14], item[15],    item[13], item[12].strip(), item[10], (item[10]+item[11]) , item[0:9])
            f.write(s.encode("UTF-8"))
        
        record = name, subname, t, items[0][13] if items and items[0] else None
        open(recordfile, 'a').write(repr(record) + "\n")

